package bot;

import java.util.Scanner;

public class InputLineSegmenter {	
	private String sender;
	private String host;
	private String type;
	private String receiver;
	private String message;

	
	public void segment(String line) {
		if (line.startsWith("PING ")) {
			type = "PING";
			message = line.substring(5);
			return;
		}
		
		Scanner scan = new Scanner(line);
		
		sender = scan.next();
		type = scan.next();
		receiver = scan.next();
		
		if (sender.contains("@")) {
			host = sender.substring(sender.indexOf("@") + 1);
			sender = sender.substring(1, sender.indexOf("!"));
		} else {
			host = "";
		}
		
		if (scan.hasNext()) {
			message = scan.nextLine().substring(1);
		}
	}

	public String getSender() {
		return sender;
	}

	public String getHost() {
		return host;
	}

	public String getType() {
		return type;
	}

	public String getReceiver() {
		if (receiver.startsWith(":")) {
			return receiver.substring(1);
		}
		return receiver;
	}

	public String getMessage() {
		if (message.startsWith(":")) {
			return message.substring(1);
		}
		return message;
	}
}
